--[[
VHeWS example of a simple data service as concept test.

This Code is part of the graduation project of Pedro Bittencourt e Silva,
VHeWS.
Developed to be used with Kepler running on Xavante (not tested in Apache)

@author Pedro Bittencourt
--]]
local http = require("socket.http")

local ip = cgilua.QUERY.IP
local fname = cgilua.QUERY.fname
local file = io.open("sensordata.dat","a") --open file in append mode
local sensorAdd = "http://"..ip.."/?fname="..fname
local sum = 0
for i=1,3 do
	val,err = http.request(sensorAdd)
	if err ~= 200 then
		error("connection fail: "..tostring(err));
	end
	for i=0,1000 do 
		for i=0,1000 do
			os.clock()
		end
	end
	file:write(os.date().." "..tostring(sum).."\n")
	sum = sum + val
end
print(sum/3)
file:close()

